<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!--引用CW标签  -->
<%@ taglib uri="/WEB-INF/taglib/cw" prefix="CW" %>
<!--引用struts标签  -->
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="<%=basePath%>js/commons/common_list.js"></script>
<link href="<%=basePath%>css/en/list.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
	$(document).ready(function() {
		//显示操作结果
		var actionResult = $("#actionResult").val();
		if(actionResult=="success"){
			art.dialog.tips('操作成功');
		}else if(actionResult=="error"){
			art.dialog.tips('操作失败！');
		}
	});
	function _add() {
	     //设置请求的url
	    var url = "<%=basePath%>/role/gotoAdd.action";
		location.href=url;
	}
	function _modify(RoleName) {
		 //设置请求的url 
		var _url = "<%=basePath%>/role/toModifyRole.action?RoleName="+encodeURI(RoleName);
		location.href=_url;
	}
	function delRole(RoleName) {
		$.ajax({ 
			type: "post",  
			url : "<%=basePath%>/roleAjax/getRoleManagerCount.action",
			data:"RoleName="+encodeURI(RoleName),
			success: function(data){ 
			    if(data=='true'){
				  	art.dialog.confirm('确认删除所选角色?', function(){
						document.roleListMain.action="<%=basePath%>/role/deleteRole.action?RoleName="+encodeURI(RoleName);
						document.roleListMain.submit();
					}, function(){
					     art.dialog.tips('取消操作');
					});
			  	}
			  	if(data=='false'){
			 		art.dialog.confirm('该角色下存在用户，确认删除角色？', function(){
						document.roleListMain.action="<%=basePath%>/role/deleteRole.action?RoleName="+encodeURI(RoleName);
						document.roleListMain.submit();
					}, function(){
					    art.dialog.tips('取消操作');
					});
			  	}
			}
		});
	}
	//刷新页面
	function _resresh(){
		document.roleListMain.action="<%=basePath%>/role/findAllRoles.action";
		document.roleListMain.submit();
	}
	function delRoles(){
		var RoleName = getCheckedValue();
		if(RoleName==""||RoleName==null){
			art.dialog.tips('请至少选择一项');
		}else{
			$.ajax({  
				type: "post",  
				url :  "<%=basePath%>/roleAjax/getRoleManagerCount.action",
				data:"RoleName="+encodeURI(RoleName),
				success: function(data){ 
			    if(data=='true'){
				  	art.dialog.confirm('确认删除所选角色?', function(){
						document.roleListMain.action="<%=basePath%>/role/deleteRole.action?RoleName="+encodeURI(RoleName);
						document.roleListMain.submit();
					}, function(){
					    art.dialog.tips('取消操作');
					});
			  	}
			    else if(data=='false'){
			 		art.dialog.confirm('该角色下存在用户，确认删除角色？', function(){
						document.roleListMain.action="<%=basePath%>/role/deleteRole.action?RoleName="+ encodeURI(RoleName);
						document.roleListMain.submit();
						}, function() {
							art.dialog.tips('取消操作');
						});
					}
				}
			});

		}
	}
	function selectRight(name) {
		//设置请求的url 
		var _url = "<%=basePath%>/jsp/cwises/system/role/rightModule_tree.jsp";
		art.dialog.data('name',name);
		//调用art.dialog组件弹出窗口 采用iframe方式
		art.dialog.open(_url,{ 
		 	lock: true,//背景锁定
	    	background: '#BFBFBF', // 背景色
	    	opacity: 0.5,	// 透明度
			title : '选择模块',
			width: '400px',
			height: '400px',
			drag: false,//禁止拖动
			resize: false,//禁止改变大小
			ok : function() {
				var iframe = this.iframe.contentWindow;
				if (!iframe.document.body) {
					/* 页面没有加载完毕！ */
					art.dialog.tips('加载失败');
					return false;
				}
				var form = iframe.document.getElementById("selRoleForm");
				form.submit();
			},
			cancel : true
		}); 
	}
 	function _changeStatus(obj){
		var sCode = obj.id;
		var dictStatus = obj.name;
		var DictName;
		var css = "";
		if(dictStatus==1){
			css="statusEnabled";
			DictName = "0";
		}else{
			css = "statusDisabled";
			DictName = "1";
		}
		$.ajax({  
		    type: "post",  
		    async: false,
		    url: "<%=basePath%>/roleAjax/changeRoleStatus.action",
			data : "sCode=" + sCode + "&dictStatus=" + dictStatus,
			success : function(data) {
				if (data == 'true') {
					art.dialog.tips('操作成功');
					$("#" + sCode).attr("class", css);
					$("#" + sCode).attr("name", DictName);
				} else {
					art.dialog.tips('操作失败');
				}
			}
		});

	} 
</script>
</head>

<body style="background-color: #EEEEEE;">
	<form action="role/getAllRoles.action" id="roleListMain" name="roleListMain" method="post">
		<s:hidden name="actionResult" id="actionResult"></s:hidden>
		<div class="pageheader">
			<div class="pagetitle">
				角色管理
			</div>
			<!-- 列表头 -->
			<div class="pageheadercontent">
				<!-- 工具栏 -->
				<div class="toolbar">
					<!-- 视图 -->
					<div class="toolbarleft"></div>
					<!-- 操作 -->
					<div class="toolbarright">
						<input name="add" type="button" value="添加" class="addbtn" onclick="_add();return false;">
						<input name="delete" type="button" value="删除" class="delbtn" onclick="delRoles();return false;">
						<input name="refresh" type="button" value="刷新" class="refbtn" onclick="_resresh();return false;">
					</div>
				</div>
			</div>
		</div>
		<table class="gridview tablesorter">
			<thead>
				<tr class="gridview_color">
					<th width="40px"><input type="checkbox" name="chk_all" id="chk_all" /></th>
					<th width="40px">序号</th>
					<th>角色名称</th>
					<th>角色描述</th>
					<th>角色排序号</th>
					<th>创建人</th>
					<th>创建时间</th>
					<th>状态</th>
					<th width="80px">操作</th>
				</tr>
			</thead>
			<tbody>
				<s:if test="listRoleManager.size()>0">
					<s:iterator value="listRoleManager" var="role" status="status">
						<s:if test="%{#status.count%2 == 0}"><tr class="gridview_color"></s:if>
							<td><input type="checkbox" name="chk_list" id="chk_list_<s:property value="#status.count" />" value="<s:property value="RoleName" />" /></td>
							<td><s:property value="#status.count" /></td>
							<td title="<s:property value="RoleName" />"><s:property value="RoleName" /></td>
							<td title="<s:property value="RoleRemark" />"><s:property value="RoleRemark" /></td>
							<td title="<s:property value="RoleNumber" />"><s:property value="RoleNumber" /></td>
							<td><CW:dataValue property="CreatePerson" field="CreatePerson" person="true"></CW:dataValue></td>
							<td><s:date name="CreateTime" format="yyyy/MM/dd hh:mm:ss" /></td>
							<td><input type="button"
								class="<s:if test="%{Status == 0}">statusDisabled</s:if><s:if test="%{Status == 1}">statusEnabled</s:if>"
								name="<s:if test="%{Status == 0}">1</s:if><s:if test="%{Status == 1}">0</s:if>" id="<s:property value="RoleName" />"
								onclick="_changeStatus(this);return false;"></td>
							<td><img id="divOperation<s:property value="RoleName" />" src="images/buttonicon/operation.png" class="operationbtn" onclick="display('<s:property value="RoleName" />',event)">
								<div id="divhidden<s:property value="RoleName" />" class="listmenu" style="display: none;" onmouseleave="onhidden('<s:property value="RoleName" />')">
									<ul>
										<li><a href="#" onclick="_modify('<s:property value="RoleName" />');return false;">修改</a></li>
										<li><a href="#" onclick="delRole('<s:property value="RoleName" />');return false;">删除</a></li>
										<li><a href="#" onclick="selectRight('<s:property value="RoleName" />');return false;">配置</a></li>
									</ul>
								</div>
							</td>
						</tr>
					</s:iterator>
				</s:if>
			</tbody>
		</table>
		<s:else>
			<jsp:include page="../../../common/nullPage.jsp" />
		</s:else>
		<!--分页条-->
		<CW:page property="page" url="/role/getAllRoles.action"></CW:page>
	</form>
	<span class="_height"></span>
</body>
</html>
